

/**
 *     P2.java
 *
 *       Extends LinkUtilPlayer with simple animation of colors on links. 
 */

import SSF.Net.*;
import SSF.OS.NetFlow.BytesUtil;
import com.renesys.raceway.views.*;
import java.awt.Color;

public class P2 extends LinkUtilPlayer {

    public void play(Stream.Record r) {
	int typeid   = r.type_code;
	int srcid    = r.source_code;
	double time  = r.timestamp;
	byte[] buf   = r.bytes;
	int bindex   = r.offset;
	int length   = r.length;
	
        if (!stream.getRecordTypeString(typeid).equals
	    ("SSF.Net.QueueRecord_2")) 
	    return; // let someone else render it
        
	int sumct = BytesUtil.bytesToInt(buf,bindex+0);
	int sumdrop = BytesUtil.bytesToInt(buf,bindex+4);
	int ct = BytesUtil.bytesToInt(buf,bindex+8);
	int drop = BytesUtil.bytesToInt(buf,bindex+12);
	
	String src_nhi = stream.getRecordSourceString(srcid);

	Raceway.VisibleLink L = stream.raceway().getVisibleLink(src_nhi);

	if (null == L) {
	    System.err.println("No link for "+src_nhi);
	}
	if (null != L) {
	    if (ct>1000)
		L.setStrokeColor(Color.red);
	    else if (ct>100) 
		L.setStrokeColor(Color.orange);
	    else if (ct>10) 
		L.setStrokeColor(Color.yellow);
	    else if (ct>0) 
		L.setStrokeColor(Color.green);
	    else 
		L.setStrokeColor(Color.gray);

	    L.refresh();
	} 
    }
}

